package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.YtConstructionContract;
import com.ruoyi.system.service.IYtConstructionContractService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 施工合同Controller
 * 
 * @author magichaohao
 * @date 2021-05-18
 */
@Controller
@RequestMapping("/system/contract")
public class YtConstructionContractController extends BaseController
{
    private String prefix = "system/contract";

    @Autowired
    private IYtConstructionContractService ytConstructionContractService;

    @RequiresPermissions("system:contract:view")
    @GetMapping()
    public String contract()
    {
        return prefix + "/contract";
    }

    /**
     * 查询施工合同列表
     */
    @RequiresPermissions("system:contract:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YtConstructionContract ytConstructionContract)
    {
        startPage();
        List<YtConstructionContract> list = ytConstructionContractService.selectYtConstructionContractList(ytConstructionContract);
        return getDataTable(list);
    }

    /**
     * 导出施工合同列表
     */
    @RequiresPermissions("system:contract:export")
    @Log(title = "施工合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YtConstructionContract ytConstructionContract)
    {
        List<YtConstructionContract> list = ytConstructionContractService.selectYtConstructionContractList(ytConstructionContract);
        ExcelUtil<YtConstructionContract> util = new ExcelUtil<YtConstructionContract>(YtConstructionContract.class);
        return util.exportExcel(list, "施工合同数据");
    }

    /**
     * 新增施工合同
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存施工合同
     */
    @RequiresPermissions("system:contract:add")
    @Log(title = "施工合同", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YtConstructionContract ytConstructionContract)
    {
        return toAjax(ytConstructionContractService.insertYtConstructionContract(ytConstructionContract));
    }

    /**
     * 修改施工合同
     */
    @GetMapping("/edit/{constructionId}")
    public String edit(@PathVariable("constructionId") Long constructionId, ModelMap mmap)
    {
        YtConstructionContract ytConstructionContract = ytConstructionContractService.selectYtConstructionContractById(constructionId);
        mmap.put("ytConstructionContract", ytConstructionContract);
        return prefix + "/edit";
    }

    /**
     * 修改保存施工合同
     */
    @RequiresPermissions("system:contract:edit")
    @Log(title = "施工合同", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YtConstructionContract ytConstructionContract)
    {
        return toAjax(ytConstructionContractService.updateYtConstructionContract(ytConstructionContract));
    }

    /**
     * 删除施工合同
     */
    @RequiresPermissions("system:contract:remove")
    @Log(title = "施工合同", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ytConstructionContractService.deleteYtConstructionContractByIds(ids));
    }
}
